package org.meteorshower.employee_depart.controller;

import com.baomidou.mybatisplus.extension.service.IService;
import org.meteorshower.cms_common.controller.BaseController;
import org.meteorshower.cms_common.result.ResponseObj;
import org.meteorshower.employee_depart.entity.Department;
import org.meteorshower.employee_depart.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 部门类控制层
 * @author Meteorshower
 * @version 1.0
 * @since 2025-06-07
 * @see org.meteorshower.cms_common.controller.BaseController 继承自BaseController
 * @apiNote 默认CRUD已实现，更多额外功能需要额外添加
 * */
@RequestMapping("api/department")
@RestController
@ResponseBody
public class DepartmentController extends BaseController<Department> {

    private final DepartmentService departmentService;

    @Autowired
    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @Override
    public IService<Department> getService() {
        return this.departmentService;
    }
    /**
     * 根据部门名称查询
     * @param name 部门名称，可模糊查询
     * @return 部门列表
     * */
    @GetMapping("/name/{name}")
    public ResponseObj<List<Department>> getDepartmentByName(@PathVariable("name") String name) {
        return ResponseObj.ok(departmentService.getByName(name));
    }

}
